//Random Game Engine
//Copyright (C) 2013  Nikolay Dionisov

//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with this program.  If not, see <http://www.gnu.org/licenses/>.

#ifndef __THREADPOOL_H_INCLUDED__
#define __THREADPOOL_H_INCLUDED__


#include <memory>
#include <vector>
#include <thread>
#include "..\Managers\Task Manager\GeneralWorks.h"
#include "..\Managers\ManagerContainer.h"
namespace re
{
	namespace core
	{
		class Thread
		{
		public:
			Thread() { finish = false; }
			~Thread() {}
			friend class ThreadPool;
		private:
			void MainLoop(ITaskManager* feed);
			static void Run(Thread* thread, ITaskManager* feed);
		public:
			void LaunchThread(ITaskManager* feed);
		private:
			std::thread thread_;
		protected:
			bool finish;
		};
		typedef std::shared_ptr<Thread> ThreadPtr;
		typedef std::vector<ThreadPtr> ThreadList;
		class ThreadPool
		{
		public:
			ThreadPool() {}
			~ThreadPool() {}

			void AllocateThreads(ManagerContainer* managers);
			void Release(ITaskManager* tasks);
		private:
			ThreadList threads_;
		};
	}
}



#endif